/**
 * 今日达订单
 */
var queryorderTodaySearch = function() {
	var queryOrdersTodayFieldSet = new Ext.form.FieldSet({
				id : 'queryOrdersTodayFieldSet',
				title : '查询条件',
				collapsible : true,// 可折叠
				buttonAlign : 'center',
				keys : [{
							key : 13, // 13代表回车
							fn : queryOrdersToday,
							scope : this
						}],
				items : [{
					layout : 'column',
					border : false,
					items : [{
								columnWidth : .25,
								layout : 'form',
								border : false,
								items : [{
											xtype : 'textfield',
											name : 'id',
											anchor : '100%',
											fieldLabel : '订单编号'
										}]
							}, {
								columnWidth : .25,
								layout : 'form',
								border : false,
								items : [{
											xtype : 'textfield',
											anchor : '100%',
											fieldLabel : '订单编码',
											name : "orderCode"
										}]
							}, {
								columnWidth : .25,
								layout : 'form',
								border : false,
								items : [{
											xtype : 'textfield',
											anchor : '100%',
											fieldLabel : '手机号',
											name : "userPhone"
										}]
							}, {
								columnWidth : .25,
								layout : 'form',
								border : false,
								items : [{
									xtype : 'localcommonbox',
									anchor : '100%',
									fieldLabel : '支付方式',
									hiddenName : 'payType',
									loaclarr : [['0', '微信'], ['1', '支付宝'],
											['', '全部']]
								}]
							}]
				}, {
					layout : 'column',
					border : false,
					items : [{
						columnWidth : .25,
						layout : 'form',
						border : false,
						items : [{
									xtype : 'localcommonbox',
									anchor : '100%',
									fieldLabel : '支付状态',
									hiddenName : 'payStatus',
									loaclarr : [['0', '未支付'], ['1', '已支付'],
											['', '全部']]
								}]
					}, {
						layout : 'column',
						border : false,
						items : [{
									text : '查询',
									xtype : 'button',
									width : 70,
									handler : function() {
										queryOrdersToday();
									},
									style : {
										marginLeft : "100px",
										marginRight : "10px"
									}
								}, {
									text : '重置',
									xtype : 'button',
									width : 70,
									handler : function() {
										queryorderTodayForm.getForm().reset();
									}
								}]
					}]

				}]
			});
	fieldSetListeners(['queryOrdersTodayFieldSet', 'queryorderTodayForm',
					'orderTodayManagerGrid'], [0.16, 0.84]);

	var queryorderTodayForm = new Ext.form.FormPanel({
				id : 'queryorderTodayForm',
				anchor : '100% 16%',
				frame : true,
				labelAlign : 'right',
				bodyBorder : false,
				items : [queryOrdersTodayFieldSet]
			});
	return queryorderTodayForm;
};

/**
 * grids
 */
var orderTodayManagerGrid = function() {
	// 定义表的每列（对应表头信息）
	var orderTodayCm = new Ext.grid.ColumnModel([{
				dataIndex : "id",
				header : "订单编号",
				sortable : false,
				width : 60
			}, {
				dataIndex : "orderCode",
				header : "订单编码",
				sortable : false,
				width : 160
			}, {
				dataIndex : "userPhone",
				header : "联系人手机号",
				sortable : false,
				width : 100

			}, {
				dataIndex : "payType",
				header : "支付方式",
				sortable : false,
				width : 70,
				renderer : function(value) {
					return PmsUtil.PayType(value);
				}
			}, {
				dataIndex : "payStatus",
				header : "订单状态",
				sortable : false,
				width : 60,
				renderer : function(value) {
					return '<font color=\"#FF0000\" >'
							+ PmsUtil.OrderPayStatus(value) + '</font>';
				}
			}, {
				dataIndex : "totalAmount",
				header : "订单金额",
				sortable : false,
				width : 70,
				renderer : function(value) {
					return PmsUtil.Price(value);
				}
			}, {
				dataIndex : "outTradeNo",
				header : "交易单号",
				sortable : false,
				width : 160
			}, {
				dataIndex : "payNo",
				header : "流水号",
				sortable : false,
				width : 180
			}, {
				dataIndex : "remark",
				header : "备注",
				sortable : false,
				width : 100,
				renderer : function(value, meta, record) {
					if (value) {
						meta.attr = 'ext:qtitle="备注:" ext:qtip="' + value + '"';
						return '<font color=\"#FF0000\" >' + value + '</font>';;
					}
				}
			}, {
				dataIndex : "createdDate",
				header : "创建时间",
				sortable : false,
				width : 130
			}]);

	// 定义分析器
	var orderManagerReader = new Ext.data.JsonReader({
				totalProperty : "totalCount",
				root : "list",
				fields : [{
							name : "id"
						}, {
							name : "orderCode"
						}, {
							name : "userPhone"
						}, {
							name : "payStatus"
						}, {
							name : "payType"
						}, {
							name : "payDate"
						}, {
							name : "totalAmount"
						}, {
							name : "payNo"
						}, {
							name : "outTradeNo"
						}, {
							name : "remark"
						}, {
							name : "createdDate"
						}, {
							name : "createdName"
						}]
			});

	// 取数据store
	var orderTodayViewStore = new Ext.data.Store({
				autoLoad : true,// 要加载数据必须设置为true
				proxy : new Ext.data.HttpProxy({
							url : __ctxPath + "/orderManager/selectTodayOrders"
						}),
				remoteSort : true,
				baseParams : {
					start : 0,
					limit : 25
				},
				listeners : {
					beforeload : {
						fn : function(thiz, options) {
							Ext.apply(thiz.baseParams, Ext
											.getCmp('queryorderTodayForm')
											.getForm().getValues());
						}
					}
				},
				reader : orderManagerReader
			});
	orderTodayViewStore.setDefaultSort("od.id", "desc");
	var orderTodayTb = new Ext.Toolbar({// 定义grid的toolbar
		height : 25,
		items : []
	});

	orderTodayTb.add(new Ext.scm.Button({
				text : "刷 新",
				width : 80,
				iconCls : "btn-refresh",
				hsValue : 'orderTodayManager_刷新',
				pressed : true,
				handler : function() {
					queryOrdersToday();
				}
			}));
	var orderTodayManagerGrid = new Ext.grid.GridPanel({
				id : 'orderTodayManagerGrid',
				store : orderTodayViewStore,
				cm : orderTodayCm,
				autoScroll : true,
				loadMask : true,
				stripeRows : true,
				columnLines : true,
				loadMask : {
					msg : "正在加载数据，请稍侯……"
				},
				viewConfig : {
					emptyText : '没有您想要的数据!'
				},
				anchor : '100% 84%',
				frame : true,
				tbar : orderTodayTb,
				bbar : new PG.PagingBar({
							id : 'orderTodayGridPage',
							store : orderTodayViewStore
						})
			});
	return orderTodayManagerGrid;
};

// 查询
function queryOrdersToday() {
	if (Ext.getCmp('queryorderTodayForm').getForm().isValid()) {
		var grid = Ext.getCmp('orderTodayManagerGrid');
		var store = grid.store;
		var pagesize = Ext.getCmp('orderTodayGridPage').pageSize;
		store.load({
					params : {
						start : 0,
						limit : pagesize
					}
				});
	}
}

Ext.getCmp("centerTabPanel").getActiveTab().add(queryorderTodaySearch(),
		orderTodayManagerGrid());
Ext.getCmp("centerTabPanel").getActiveTab().doLayout();